/*
 * Copyright 2008 Slava Chernyak
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License. 
 */
package com.chernyak.DataAdapter;

import java.util.*;

/** @author Slava Chernyak
 * 
 * Interface to all nodes in the abstract syntax tree. Defines methods for basic
 * lowering of the data adapter declaration to code
 *
 */
public abstract class ParserNode implements
		WriteableComparableGenerator {
	protected int ln;
	
	/** Abstract constructor keeps track of the line number for current node
	 * in the abstract syntax tree
	 * 
	 * @param ln relevant line number
	 */
	public ParserNode(int ln) {
		this.ln = ln;
	}

	/** Typecheck the current node in the syntax tree and cause all child nodes
	 * to typecheck. 
	 * 
	 * @param globalSymbolTable Outermost symbol table used for declaring data
	 * 		adapter types
	 * @param parrentSymbolTable The symbol table for the parent codeblock to
	 * 		the one being typechecked
	 */
	public abstract void typecheck(Map<String, GlobalSymbolProperties> globalSymbolTable, List<String> 
		parrentSymbolTable, String packageContext);
	
	/** Lower the data declaration statements for this node and cause all child
	 * nodes to lower theirs.
	 * 
	 * @param sink StringBuilder to write generated code to
	 */
	public abstract void lowerDeclarations(StringBuilder sink);
	
	/** Lower the equality statements for this node and cause all child nodes to
	 * lower theirs
	 * 
	 * @param sink StringBuilder to write generated code to
	 */
	public abstract void lowerEquals(StringBuilder sink);
	
	/** Lower the hashcode statements for this node and cause all child nodes to
	 * lower theirs
	 * 
	 * @param sink StringBuilder to write generated code to
	 */
	public abstract void lowerHashCode(StringBuilder sink);
	
	/** Lower the toString statements for this node and cause all child nodes to
	 * lower theirs.
	 * 
	 * @param sink StringBuilder to write generated code to
	 */
	public abstract void lowerToString(StringBuilder sink);
	
	/** Lower the parse statements for this node and cause all child nodes to
	 * lower theirs.
	 * 
	 * @param sink StringBuilder to write generated code to
	 */
	public abstract void lowerParse(StringBuilder sink);
}
